$(document).ready(init);

var pageResultVO;
var isFirstLoad = true;

function init(){
	initData();
	renderPage();
	bindEvent();
}

function initData(){
	pageResultVO = responseVO.objects["pageResultVO"];
}

function renderPage(){
	renderBookList();
	
	$("#pagination").pagination(pageResultVO.totalRecorderCount, {
 		items_per_page: pageResultVO.pageLimit, 
 		callback: loadTargetPage,
 		num_display_entries:3,
 		num_edge_entries:1,
 		link_to:"javascript:void(0)",
 		prev_text: "<",
 		next_text: ">"
	 }); 
}

function renderBookList(){
	var item;
	$('#bookList').empty();
	for(var i=0;i<pageResultVO.result.length;i++){
		item=  pageResultVO.result[i];
		$(itemRender.basicBookItem.getHtmlCode(item)).appendTo($('#bookList'));
	}
	
	
}

function bindEvent(){

}

function loadTargetPage(page_index, jq){
	
	if(isFirstLoad == true){//第一次加载数据使用从Controller中获得的requestVO，不要ajax调用
		isFirstLoad = false;
		return false;
	}
	
	var remoteUri = webappName+"/book/list/"+page_index+"/"+pageResultVO.pageLimit;
	
	$.post(remoteUri,refreshResultList,"json");
	return false; 
}

function refreshResultList(data){
	responseVO = data;
	//responseVO = eval(data);
	pageResultVO = responseVO.objects["pageResultVO"];
	renderBookList();
}